﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Framework
{
    public class SceneManager : Singleton<SceneManager>
    {
        public List<string> sceneNames;
        public string loadingImg;
        public Action onLoadFinish;

        public void BeginLoadScene(List<string> sceneNames, Action onLoadFinish, string loadingImg = "ui_loading_p")
        {
            this.sceneNames = sceneNames;
            this.onLoadFinish = onLoadFinish;
            this.loadingImg = loadingImg;
            GL.Clear(false, true, Color.black);

            UnityEngine.SceneManagement.SceneManager.LoadScene("loading", LoadSceneMode.Single);
        }

        public void EndLoadScene()
        {
            Mainloop.Instance.StartCoroutine(EndLoadSceneJob());
            
        }

        IEnumerator EndLoadSceneJob()
        {
            yield return new WaitForEndOfFrame();
            if(GameObject.Find("Loading") != null)
                GameObject.Find("Loading").SetActive(false);
        }
    }
}

